import { getToken, setToken, delToken } from "@/utils/storage"
import { LoginApi, Getuser } from '../utils/user.js'
export default {
  state () {
    return {
      token: getToken(),
      userinfo: {}
    }
  },
  mutations: {
    setUser (state, user) {
      state.userinfo = user
    },
    resetToken (state) {
      state.token = null
      delToken()
    }
  },
  actions: {
    async LoginEvent ({ commit }, data) {
      const res = await LoginApi(data)
      // console.log(res)
      setToken(res.data.token)
      const res1 = await Getuser()
      commit('setUser', res1.data)
    }
  },
  getters: {},
  namespaced: true
}